package com.weng.platform.stories.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.framework.core.exception.GlobalServiceException;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.platform.stories.entity.Iterations;
import com.weng.platform.stories.mapper.IterationsMapper;
import com.weng.platform.stories.model.dto.CourseDto;
import com.weng.platform.stories.model.req.CourseListReq;
import com.weng.platform.stories.model.vo.IterationsVo;
import com.weng.platform.stories.service.IIterationsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;


/**
 * 课程信息 服务实现类
 *
 * @author wenghui
 * @date 2020-05-17 13:16:31
 *
 */ 
@Slf4j
@Service
public class IterationsServiceImpl extends BaseServiceImpl<IterationsMapper, Iterations> implements IIterationsService {
	@Autowired
	private IterationsMapper iterationsMapper;





    @Override
    public IterationsVo getCourseRel(String courseId) {
        Iterations iterations = this.getById(courseId);
        IterationsVo iterationsVo = Convert.convert(IterationsVo.class, iterations);
        return iterationsVo;
    }



	/**
	 * 分页查询课程信息
	 * @return
	 */
	@Override
	public IPage<CourseDto> list(Integer pageNo, Integer pageSize, CourseListReq paramData) {
		IPage<CourseDto> page = new PageModel<>(pageNo,pageSize);
        List<CourseDto> list =  iterationsMapper.page(page,paramData);
        page.setRecords(list);
		return page;
	}






    /**
	 * 获取单个课程信息
	 * @param id
	 * @return
	 */
	@Override
	public Iterations getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个课程信息
	 * @param courseReq
	 * @return
	 */
	@Override
	public Iterations add(IterationsVo courseReq) throws GlobalServiceException {
        Iterations iterations = Convert.convert(Iterations.class, courseReq);
        iterationsMapper.insert(iterations);
		return iterations;
	}





	/**
	 * 更新单个课程信息
	 * @param courseReq
	 * @return
	 * @throws GlobalServiceException
	 */
	@Override
	public int update(IterationsVo courseReq) throws GlobalServiceException {
        Iterations iterations = Convert.convert(Iterations.class, courseReq);
		return iterationsMapper.updateById(iterations);

	}


	@Override
    @Transactional
	public ResponseData removeByIds(String ids) {
		String[] courseIds = ids.split(",");
        return ResponseData.success();
	}

}
